package com.dzzw.Servlet.ReplyServlet;

import com.dzzw.Dao.ReplyDao;
import com.dzzw.Model.Reply;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/View/ReplyAddServlet")
public class ReplyAddServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    ReplyDao replyDao = new ReplyDao();
    public ReplyAddServlet(){
        super();
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        int forum_id = Integer.parseInt(request.getParameter("forum_id"));
        int user_id = Integer.parseInt(request.getParameter("user_id"));
        String response_content = request.getParameter("response_content");
        Reply reply = new Reply();
        reply.setForum_id(forum_id);
        reply.setUser_id(user_id);
        reply.setResponse_content(response_content);
        replyDao.ReplyAdd(reply);
        response.sendRedirect("SelectAllForumServlet");
    }
}
